package com.zmn.oms.services.impl.pricefeedback;

import com.zmn.oms.model.entity.pricefeedback.PriceFeedback;
import com.zmn.oms.model.entity.pricefeedback.PriceFeedbackQuery;
import com.zmn.oms.persistence.interfaces.pricefeedback.PriceFeedbackDao;
import com.zmn.oms.services.interfaces.pricefeedback.PriceFeedbackService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * 描述: 价格反馈表基础接口实现类
 *
 * @author weilai
 * @since 2022-09-07 11:23:26
 **/
@Slf4j
@Service
public class PriceFeedbackServiceImpl implements PriceFeedbackService {

    private static final String TAG = "价格反馈表基础服务接口";

    @Resource
    private PriceFeedbackDao priceFeedbackDao;

    /**
     * 描述: 根据id查询数据
     *
     * @param feedbackId id
     * @author weilai
     * @since 2022-09-07 11:23:26
     **/
    @Override
    public PriceFeedback findById(Integer feedbackId) {

        if (Objects.isNull(feedbackId)) {
            log.error("[{}],根据id查询数据feedbackId为null", TAG);
            return null;
        }
        return priceFeedbackDao.findById(feedbackId);
    }

    /**
     * 描述: 按条件查询数据 支持分页
     *
     * @param query 查询对象
     * @author weilai
     * @since 2022-09-07 11:23:26
     **/
    @Override
    public List<PriceFeedback> listPageByQuery(PriceFeedbackQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        Integer count = countByQuery(query);
        query.setTotalCount(count);
        return priceFeedbackDao.listPageByQuery(query);
    }

    /**
     * 描述: 按条件查询数据 不支持分页
     *
     * @param query 查询对象
     * @author weilai
     * @since 2022-09-07 11:23:26
     **/
    @Override
    public List<PriceFeedback> listByQuery(PriceFeedbackQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }

        return priceFeedbackDao.listByQuery(query);
    }

    /**
     * 描述: 按条件查询数据 不支持分页
     *
     * @param query 查询对象
     * @author weilai
     * @since 2022-09-07 11:23:26
     **/
    @Override
    public Integer countByQuery(PriceFeedbackQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件统计数据,query为null", TAG);
            return null;
        }
        return priceFeedbackDao.countByQuery(query);
    }


    /**
     * 描述: 根据id修改数据 id为必传
     *
     * @param priceFeedback 待修改数据
     * @return java.lang.Integer
     * @author weilai
     * @since 2022-09-07 11:23:26
     **/
    @Override
    public Integer updateByKey(PriceFeedback priceFeedback) {

        if (Objects.isNull(priceFeedback.getFeedbackId())) {
            log.error("[{}],根据id修改数据,priceFeedback为null", TAG);
            return null;
        }
        return priceFeedbackDao.updateByKey(priceFeedback);
    }

    /**
     * 描述: 新增数据
     *
     * @param priceFeedback 待新增数据
     * @return java.lang.Integer 主键key
     * @author weilai
     * @since 2022-09-07 11:23:26
     **/
    @Override
    public Integer insert(PriceFeedback priceFeedback) {

        if (Objects.isNull(priceFeedback)) {
            log.error("[{}],新增数据,priceFeedback为null", TAG);
            return null;
        }
        return priceFeedbackDao.insert(priceFeedback);
    }

    /**
     * 描述: 根据主键删除数据
     *
     * @param feedbackId
     * @return: 执行结果码
     * @auther: weilai
     * @since: 2022-09-07 11:23:26
     */
    @Override
    public Integer deleteByKey(Integer feedbackId) {

        if (Objects.isNull(feedbackId)) {
            log.error("[{}],根据id删除数据,feedbackId为null", TAG);
            return null;
        }
        return priceFeedbackDao.deleteByKey(feedbackId);
    }

}